package cc.autoapi.pucong.auto.flow.provider.node.controller;

import cc.autoapi.pucong.auto.flow.core.root.entity.BatchDeleteIdDto;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.provider.node.entity.dto.*;
import cc.autoapi.pucong.auto.flow.provider.node.entity.qo.NodeInfoQo;
import cc.autoapi.pucong.auto.flow.provider.node.entity.vo.NodeInfoDetailVo;
import cc.autoapi.pucong.auto.flow.provider.node.entity.vo.NodeTreeVo;
import cc.autoapi.pucong.auto.flow.provider.node.manager.NodeInfoManager;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @description 节点信息 controller
 * @create 2024-09-23
 */
@RestController
@Validated
@RequestMapping("/node/nodeInfo")
public class NodeInfoController extends AutoFlowBaseController implements AutoFlowExceptionHandler{

    @Resource
    private NodeInfoManager nodeInfoManager;

    @GetMapping("/getList")
    public Res<List<NodeTreeVo>> getList(NodeInfoQo dto) {
        List<NodeTreeVo> nodeInfoList = nodeInfoManager.getList(dto);
        return Res.ok(nodeInfoList);
    }

    @GetMapping("/getDetailById/{id}")
    public Res<NodeInfoDetailVo> getDetailById(@PathVariable("id") String id) {
        NodeInfoDetailVo nodeInfoDto = nodeInfoManager.getDetailById(id);
        return Res.ok(nodeInfoDto);
    }

    @GetMapping("/getNodeSvgByCode/{code}")
    public Res<String> getNodeSvgByCode(@PathVariable("code") String code) {
        String svg = nodeInfoManager.getNodeSvgByCode(code);
        return Res.ok(svg);
    }

    @PostMapping("/javaExeTest")
    public Res<NodeExeTestVo> javaExeTest(@Validated @RequestBody NodeExeTestDto dto) {
        NodeExeTestVo i = nodeInfoManager.javaExeTest(dto);
        return Res.ok(i);
    }

    @PostMapping("/jsExeTest")
    public Res<NodeExeTestVo> jsExeTest(@Validated @RequestBody NodeExeJsTestDto dto) {
        NodeExeTestVo i = nodeInfoManager.jsExeTest(dto);
        return Res.ok(i);
    }

    @PostMapping("/pythonExeTest")
    public Res<NodeExeTestVo> pythonExeTest(@Validated @RequestBody NodeExeJsTestDto dto) {
        NodeExeTestVo i = nodeInfoManager.pythonExeTest(dto);
        return Res.ok(i);
    }

    @PostMapping("/add")
    public Res<String> add(@RequestBody NodeInfoAddDto dto) {
        String id = nodeInfoManager.add(dto);
        return Res.ok(id);
    }

    @PostMapping("/updateById/{id}")
    public Res<Boolean> updateById(@PathVariable("id") String id,
                                   @RequestBody NodeInfoUpdateDto dto) {
        Boolean i = nodeInfoManager.updateById(id, dto);
        return Res.ok(i);
    }

    @PostMapping("/updateNodeIcon/{id}")
    public Res<Boolean> updateNodeIcon(@PathVariable("id") String id,
                                       @Validated @RequestBody NodeInfoUpdateIconDto dto) {
        Boolean i = nodeInfoManager.updateNodeIcon(id, dto);
        return Res.ok(i);
    }

    @PostMapping("/updateNodeSourceCode/{id}")
    public Res<Boolean> updateNodeSourceCode(@PathVariable("id") String id,
                                             @Validated @RequestBody NodeInfoUpdateCodeDto dto) {
        Boolean i = nodeInfoManager.updateNodeSourceCode(id, dto);
        return Res.ok(i);
    }

    @PostMapping("/enabledById/{id}")
    public Res<Boolean> enabledById(@PathVariable("id") String id) {
        Boolean i = nodeInfoManager.enabledById(id);
        return Res.ok(i);
    }

    @PostMapping("/disabledById/{id}")
    public Res<Boolean> disabledById(@PathVariable("id") String id) {
        Boolean i = nodeInfoManager.disabledById(id);
        return Res.ok(i);
    }

    @DeleteMapping("/batchDeleteByIds")
    public Res<Boolean> batchDeleteByIds(BatchDeleteIdDto dto) {
        Boolean i = nodeInfoManager.batchDeleteByIds(dto.getIdList());
        return Res.ok(i);
    }
}
